home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / mappy.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  10KB  |  413 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char mappy_scroll;
  15.  
  16. static int special_display;
  17. static int flipscreen;
  18.  
  19. /***************************************************************************
  20.  
  21.   Convert the color PROMs into a more useable format.
  22.  
  23.   mappy has one 32x8 palette PROM and two 256x4 color lookup table PROMs
  24.   (one for characters, one for sprites).
  25.  
  26.   The palette PROM is connected to the RGB output this way:
  27.  
  28.   bit 7 -- 220 ohm resistor  -- BLUE
  29.         -- 470 ohm resistor  -- BLUE
  30.         -- 220 ohm resistor  -- GREEN
  31.         -- 470 ohm resistor  -- GREEN
  32.         -- 1  kohm resistor  -- GREEN
  33.         -- 220 ohm resistor  -- RED
  34.         -- 470 ohm resistor  -- RED
  35.   bit 0 -- 1  kohm resistor  -- RED
  36.  
  37. ***************************************************************************/
  38. void mappy_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  39. {
  40.     int i;
  41.  
  42.     for (i = 0;i < Machine->drv->total_colors;i++)
  43.     {
  44.         int bit0,bit1,bit2;
  45.  
  46.         bit0 = (*color_prom >> 0) & 0x01;
  47.         bit1 = (*color_prom >> 1) & 0x01;
  48.         bit2 = (*color_prom >> 2) & 0x01;
  49.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  50.         bit0 = (*color_prom >> 3) & 0x01;
  51.         bit1 = (*color_prom >> 4) & 0x01;
  52.         bit2 = (*color_prom >> 5) & 0x01;
  53.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  54.         bit0 = 0;
  55.         bit1 = (*color_prom >> 6) & 0x01;
  56.         bit2 = (*color_prom >> 7) & 0x01;
  57.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  58.  
  59.         color_prom++;
  60.     }
  61.  
  62.     /* characters */
  63.     for (i = 0*4;i < 64*4;i++)
  64.         colortable[i] = (color_prom[(i^3)] & 0x0f) + 0x10;
  65.  
  66.     /* sprites */
  67.     for (i = 64*4;i < Machine->drv->color_table_len;i++)
  68.         colortable[i] = color_prom[i] & 0x0f;
  69. }
  70.  
  71.  
  72. static int common_vh_start(void)
  73. {
  74.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  75.         return 1;
  76.     memset (dirtybuffer, 1, videoram_size);
  77.  
  78.     if ((tmpbitmap = osd_create_bitmap (36*8,60*8)) == 0)
  79.     {
  80.         free (dirtybuffer);
  81.         return 1;
  82.     }
  83.  
  84.     return 0;
  85. }
  86.  
  87. int mappy_vh_start(void)
  88. {
  89.     special_display = 0;
  90.     return common_vh_start();
  91. }
  92.  
  93. int motos_vh_start(void)
  94. {
  95.     special_display = 1;
  96.     return common_vh_start();
  97. }
  98.  
  99. int todruaga_vh_start(void)
  100. {
  101.     special_display = 2;
  102.     return common_vh_start();
  103. }
  104.  
  105.  
  106.  
  107. /***************************************************************************
  108.  
  109.   Stop the video hardware emulation.
  110.  
  111. ***************************************************************************/
  112. void mappy_vh_stop(void)
  113. {
  114.     free(dirtybuffer);
  115.     osd_free_bitmap(tmpbitmap);
  116. }
  117.  
  118.  
  119.  
  120. WRITE_HANDLER( mappy_videoram_w )
  121. {
  122.     if (videoram[offset] != data)
  123.     {
  124.         dirtybuffer[offset] = 1;
  125.         videoram[offset] = data;
  126.     }
  127. }
  128.  
  129.  
  130. WRITE_HANDLER( mappy_colorram_w )
  131. {
  132.     if (colorram[offset] != data)
  133.     {
  134.         dirtybuffer[offset] = 1;
  135.         colorram[offset] = data;
  136.     }
  137. }
  138.  
  139.  
  140. WRITE_HANDLER( mappy_scroll_w )
  141. {
  142.     mappy_scroll = offset >> 3;
  143. }
  144.  
  145.  
  146.  
  147. void mappy_draw_sprite(struct osd_bitmap *dest,unsigned int code,unsigned int color,
  148.     int flipx,int flipy,int sx,int sy)
  149. {
  150.     if (special_display == 1) sy++;    /* Motos */
  151.  
  152.     drawgfx(dest,Machine->gfx[1],code,color,flipx,flipy,sx,sy,&Machine->drv->visible_area,
  153.         TRANSPARENCY_COLOR,15);
  154. }
  155.  
  156. WRITE_HANDLER( mappy_flipscreen_w )
  157. {
  158.     if (flipscreen != (data & 1))
  159.     {
  160.         flipscreen = data & 1;
  161.         memset(dirtybuffer,1,videoram_size);
  162.     }
  163. }
  164.  
  165. /***************************************************************************
  166.  
  167.   Draw the game screen in the given osd_bitmap.
  168.   Do NOT call osd_update_display() from this function, it will be called by
  169.   the main emulation engine.
  170.  
  171. ***************************************************************************/
  172. void mappy_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  173. {
  174.     int offs;
  175.  
  176.     /* for every character in the Video RAM, check if it has been modified */
  177.     /* since last time and update it accordingly. */
  178.     for (offs = videoram_size - 1;offs >= 0;offs--)
  179.     {
  180.         if (dirtybuffer[offs])
  181.         {
  182.             int sx,sy,mx,my;
  183.  
  184.             dirtybuffer[offs] = 0;
  185.  
  186.             if (offs >= videoram_size - 64)
  187.             {
  188.                 int off = offs;
  189.  
  190.                 if (special_display == 1)
  191.                 {
  192.                     /* Motos */
  193.                     if (off == 0x07d1 || off == 0x07d0 || off == 0x07f1 || off == 0x07f0)
  194.                         off -= 0x10;
  195.                     if (off == 0x07c1 || off == 0x07c0 || off == 0x07e1 || off == 0x07e0)
  196.                         off += 0x10;
  197.                 }
  198.  
  199.                 /* Draw the top 2 lines. */
  200.                 mx = (off - (videoram_size - 64)) / 32;
  201.                 my = off % 32;
  202.  
  203.                 sx = mx;
  204.                 sy = my - 2;
  205.             }
  206.             else if (offs >= videoram_size - 128)
  207.             {
  208.                 int off = offs;
  209.  
  210.                 if (special_display == 2)
  211.                 {
  212.                     /* Tower of Druaga */
  213.                     if (off == 0x0791 || off == 0x0790 || off == 0x07b1 || off == 0x07b0)
  214.                         off -= 0x10;
  215.                     if (off == 0x0781 || off == 0x0780 || off == 0x07a1 || off == 0x07a0)
  216.                         off += 0x10;
  217.                 }
  218.  
  219.                 /* Draw the bottom 2 lines. */
  220.                 mx = (off - (videoram_size - 128)) / 32;
  221.                 my = off % 32;
  222.  
  223.                 sx = mx + 34;
  224.                 sy = my - 2;
  225.             }
  226.             else
  227.             {
  228.                 /* draw the rest of the screen */
  229.                 mx = offs % 32;
  230.                 my = offs / 32;
  231.  
  232.                 sx = mx + 2;
  233.                 sy = my;
  234.             }
  235.  
  236.             if (flipscreen)
  237.             {
  238.                 sx = 35 - sx;
  239.                 sy = 59 - sy;
  240.             }
  241.  
  242.             drawgfx(tmpbitmap,Machine->gfx[0],
  243.                     videoram[offs],
  244.                     colorram[offs] & 0x3f,
  245.                     flipscreen,flipscreen,8*sx,8*sy,
  246.                     0,TRANSPARENCY_NONE,0);
  247.         }
  248.     }
  249.  
  250.     /* copy the temporary bitmap to the screen */
  251.     {
  252.         int scroll[36];
  253.  
  254.         for (offs = 0;offs < 2;offs++)
  255.             scroll[offs] = 0;
  256.         for (offs = 2;offs < 34;offs++)
  257.             scroll[offs] = -mappy_scroll;
  258.         for (offs = 34;offs < 36;offs++)
  259.             scroll[offs] = 0;
  260.  
  261.         if (flipscreen)
  262.         {
  263.             for (offs = 0;offs < 36;offs++)
  264.                 scroll[offs] = 224 - scroll[offs];
  265.         }
  266.  
  267.         copyscrollbitmap(bitmap,tmpbitmap,0,0,36,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  268.     }
  269.  
  270.     /* Draw the sprites. */
  271.     for (offs = 0;offs < spriteram_size;offs += 2)
  272.     {
  273.         /* is it on? */
  274.         if ((spriteram_3[offs+1] & 2) == 0)
  275.         {
  276.             int sprite = spriteram[offs];
  277.             int color = spriteram[offs+1];
  278.             int x = (spriteram_2[offs+1]-40) + 0x100*(spriteram_3[offs+1] & 1);
  279.             int y = 28*8-spriteram_2[offs];
  280.             int flipx = spriteram_3[offs] & 1;
  281.             int flipy = spriteram_3[offs] & 2;
  282.  
  283.             if (flipscreen)
  284.             {
  285.                 flipx = !flipx;
  286.                 flipy = !flipy;
  287.             }
  288.  
  289.             switch (spriteram_3[offs] & 0x0c)
  290.             {
  291.                 case 0:        /* normal size */
  292.                     mappy_draw_sprite(bitmap,sprite,color,flipx,flipy,x,y);
  293.                     break;
  294.  
  295.                 case 4:        /* 2x horizontal */
  296.                     sprite &= ~1;
  297.                     if (!flipx)
  298.                     {
  299.                         mappy_draw_sprite(bitmap,sprite,color,flipx,flipy,x,y);
  300.                         mappy_draw_sprite(bitmap,1+sprite,color,flipx,flipy,x+16,y);
  301.                     }
  302.                     else
  303.                     {
  304.                         mappy_draw_sprite(bitmap,sprite,color,flipx,flipy,x+16,y);
  305.                         mappy_draw_sprite(bitmap,1+sprite,color,flipx,flipy,x,y);
  306.                     }
  307.                     break;
  308.  
  309.                 case 8:        /* 2x vertical */
  310.                     sprite &= ~2;
  311.                     if (!flipy)
  312.                     {
  313.                         mappy_draw_sprite(bitmap,2+sprite,color,flipx,flipy,x,y);
  314.                         mappy_draw_sprite(bitmap,sprite,color,flipx,flipy,x,y-16);
  315.                     }
  316.                     else
  317.                     {
  318.                         mappy_draw_sprite(bitmap,sprite,color,flipx,flipy,x,y);
  319.                         mappy_draw_sprite(bitmap,2+sprite,color,flipx,flipy,x,y-16);
  320.                     }
  321.                     break;
  322.  
  323.                 case 12:        /* 2x both ways */
  324.                     sprite &= ~3;
  325.                     if (!flipx && !flipy)
  326.                     {
  327.                         mappy_draw_sprite(bitmap,2+sprite,color,flipx,flipy,x,y);
  328.                         mappy_draw_sprite(bitmap,3+sprite,color,flipx,flipy,x+16,y);
  329.                         mappy_draw_sprite(bitmap,sprite,color,flipx,flipy,x,y-16);
  330.                         mappy_draw_sprite(bitmap,1+sprite,color,flipx,flipy,x+16,y-16);
  331.                     }
  332.                     else if (flipx && flipy)
  333.                     {
  334.                         mappy_draw_sprite(bitmap,1+sprite,color,flipx,flipy,x,y);
  335.                         mappy_draw_sprite(bitmap,sprite,color,flipx,flipy,x+16,y);
  336.                         mappy_draw_sprite(bitmap,3+sprite,color,flipx,flipy,x,y-16);
  337.                         mappy_draw_sprite(bitmap,2+sprite,color,flipx,flipy,x+16,y-16);
  338.                     }
  339.                     else if (flipy)
  340.                     {
  341.                         mappy_draw_sprite(bitmap,sprite,color,flipx,flipy,x,y);
  342.                         mappy_draw_sprite(bitmap,1+sprite,color,flipx,flipy,x+16,y);
  343.                         mappy_draw_sprite(bitmap,2+sprite,color,flipx,flipy,x,y-16);
  344.                         mappy_draw_sprite(bitmap,3+sprite,color,flipx,flipy,x+16,y-16);
  345.                     }
  346.                     else /* flipx */
  347.                     {
  348.                         mappy_draw_sprite(bitmap,3+sprite,color,flipx,flipy,x,y);
  349.                         mappy_draw_sprite(bitmap,2+sprite,color,flipx,flipy,x+16,y);
  350.                         mappy_draw_sprite(bitmap,1+sprite,color,flipx,flipy,x,y-16);
  351.                         mappy_draw_sprite(bitmap,sprite,color,flipx,flipy,x+16,y-16);
  352.                     }
  353.                     break;
  354.             }
  355.         }
  356.     }
  357.  
  358.     /* Draw the high priority characters */
  359.     for (offs = videoram_size - 1;offs >= 0;offs--)
  360.     {
  361.         if (colorram[offs] & 0x40)
  362.         {
  363.             int sx,sy,mx,my;
  364.  
  365.                 if (offs >= videoram_size - 64)
  366.                 {
  367.                     /* Draw the top 2 lines. */
  368.                     mx = (offs - (videoram_size - 64)) / 32;
  369.                     my = offs % 32;
  370.  
  371.                     sx = mx;
  372.                     sy = my - 2;
  373.  
  374.                     sy *= 8;
  375.                 }
  376.                 else if (offs >= videoram_size - 128)
  377.                 {
  378.                     /* Draw the bottom 2 lines. */
  379.                     mx = (offs - (videoram_size - 128)) / 32;
  380.                     my = offs % 32;
  381.  
  382.                     sx = mx + 34;
  383.                     sy = my - 2;
  384.  
  385.                     sy *= 8;
  386.                 }
  387.                 else
  388.                 {
  389.                     /* draw the rest of the screen */
  390.                     mx = offs % 32;
  391.                     my = offs / 32;
  392.  
  393.                     sx = mx + 2;
  394.                     sy = my;
  395.  
  396.                     sy = (8*sy-mappy_scroll);
  397.                 }
  398.  
  399.                 if (flipscreen)
  400.                 {
  401.                     sx = 35 - sx;
  402.                     sy = 216 - sy;
  403.                 }
  404.  
  405.                 drawgfx(bitmap,Machine->gfx[0],
  406.                         videoram[offs],
  407.                         colorram[offs] & 0x3f,
  408.                         flipscreen,flipscreen,8*sx,sy,
  409.                         0,TRANSPARENCY_COLOR,31);
  410.         }
  411.     }
  412. }
  413.